﻿using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DetectScars.common
{
    internal class Connect
    {
        //头标识
        public UInt16 U0_Header = 0x0303;
        //头标识
        public UInt16 U1_Header = 0x3030;
        //通道号
        public UInt16 U2_ChannelNum;
        //启停
        public UInt16 U3_StartStop;
        //滤波器
        public UInt16 U4_Filter;
        //重复频率
        public UInt16 U5_RepetitionFrequency;
        //脉冲宽度
        public UInt16 U6_PulseWidth = 200;
        //增益
        public UInt16 U7_Gain;
        //采样频率
        public UInt16 U8_SamplingFrequency = 0;
        //脉冲位移低16位
        public UInt16 U9_PulseDisplacement;
        //扫描深度低16位
        public UInt16 U10_ScanDepth;
        //
        public UInt16 U11_ = 0;
        //通道延时 并行时使用
        public UInt16 U12_RepetitionFrequency = 1;
        //
        public UInt16 U13_ = 0;
        //闸门0起始低16位
        public UInt16 U14_Gate0Start;
        //闸门0宽度低16位
        public UInt16 U15_Gate0Width;
        //闸门0幅度%
        public UInt16 U16_Gate0Threshold;
        //闸门1起始低16位
        public UInt16 U17_Gate1Start;
        //闸门1宽度低16位
        public UInt16 U18_Gate1Width;
        //闸门1幅度%
        public UInt16 U19_Gate1Threshold;
        //闸门2起始低16位
        public UInt16 U20_Gate2Start;
        //闸门2宽度低16位
        public UInt16 U21_Gate2Width;
        //闸门2幅度%
        public UInt16 U22_Gate2Threshold;
        //闸门2是否开启跟踪
        public UInt16 U23_Gate2Tracking;
        //固定取值宽度
        public UInt16 U24_ = 5;
        //
        public UInt16 U25_ = 400;
        //设备每次发送数据的重复次数，根据重复频率不同设置
        public UInt16 U26_RepetitionFrequency2;
        //io
        public UInt16 U27_ = 0;
        //数据请求类型
        public UInt16 U28_DataType;
        //门内放大
        public UInt16 U29_GateMagnify;
        //抑制    
        public UInt16 U30_ = 0;
        //降噪
        public UInt16 U31_ = 0;
        //脉冲位移高16位
        public UInt16 U32_PulseDisplacementH;
        //扫描深度高16位
        public UInt16 U33_ScanDepthH;
        //闸门0起始高 16 位
        public UInt16 U34_Gate0StartH;
        //闸门0宽度高 16 位
        public UInt16 U35_Gate0Width;
        //闸门1起始高 16 位
        public UInt16 U36_Gate1StartH;
        //闸门1宽度高 16 位
        public UInt16 U37_Gate1Width;
        //闸门2起始高 16 位
        public UInt16 U38_Gate2StartH;
        //闸门2宽度高 16 位
        public UInt16 U39_Gate2WidthH;
        //
        public UInt16 U40_ = 512;
        //跟踪闸门焦点位置低16位
        public UInt16 U41_GateTrackingFocus;
        //跟踪闸门焦点位置高16位
        public UInt16 U42_GateTrackingFocusH;
        //同步，外触发使用
        public UInt16 U43_Synchronous = 0;
        //闸门0门内调整
        public UInt16 U44_Gate0Adjust;
        //闸门1门内调整
        public UInt16 U45_Gate1Adjust;
        //闸门2门内调整
        public UInt16 U46_Gate2Adjust;
        //结束标志
        public UInt16 U47_End = 0x0f0f;
        //结束标志
        public UInt16 U48_End = 0x0f0f;
        //Dac
        public double[] DAC_x;
        //Dac
        public float[] DAC;
        //Dac
        public List<float[]> TCG;

        //临时保存
        public int enumFilter;
        public int numericUpDown25;
        public int numericUpDown26;
        public int numericUpDown34;

        public byte[] getConnect()
        {
            UInt16[] ushortArray = new UInt16[50];
            ushortArray[0] = U0_Header;
            ushortArray[1] = U1_Header;
            ushortArray[2] = U2_ChannelNum;
            ushortArray[3] = U3_StartStop;
            ushortArray[4] = U4_Filter;
            ushortArray[5] = U5_RepetitionFrequency;
            ushortArray[6] = U6_PulseWidth;
            ushortArray[7] = U7_Gain;
            ushortArray[8] = U8_SamplingFrequency;
            ushortArray[9] = U9_PulseDisplacement;
            ushortArray[10] = U10_ScanDepth;
            ushortArray[11] = U11_;
            ushortArray[12] = U12_RepetitionFrequency;
            ushortArray[13] = U13_;
            ushortArray[14] = U14_Gate0Start;
            ushortArray[15] = U15_Gate0Width;
            ushortArray[16] = U16_Gate0Threshold;
            ushortArray[17] = U17_Gate1Start;
            ushortArray[18] = U18_Gate1Width;
            ushortArray[19] = U19_Gate1Threshold;
            ushortArray[20] = U20_Gate2Start;
            ushortArray[21] = U21_Gate2Width;
            ushortArray[22] = U22_Gate2Threshold;
            ushortArray[23] = U23_Gate2Tracking;
            ushortArray[24] = U24_;
            ushortArray[25] = U25_;
            ushortArray[26] = U26_RepetitionFrequency2;
            ushortArray[27] = U27_;
            ushortArray[28] = U28_DataType;
            ushortArray[29] = U29_GateMagnify;
            ushortArray[30] = U30_;
            ushortArray[31] = U31_;
            ushortArray[32] = U32_PulseDisplacementH;
            ushortArray[33] = U33_ScanDepthH;
            ushortArray[34] = U34_Gate0StartH;
            ushortArray[35] = U35_Gate0Width;
            ushortArray[36] = U36_Gate1StartH;
            ushortArray[37] = U37_Gate1Width;
            ushortArray[38] = U38_Gate2StartH;
            ushortArray[39] = U39_Gate2WidthH;
            ushortArray[40] = U40_;
            ushortArray[41] = U41_GateTrackingFocus;
            ushortArray[42] = U42_GateTrackingFocusH;
            ushortArray[43] = U43_Synchronous;
            ushortArray[44] = U44_Gate0Adjust;
            ushortArray[45] = U45_Gate1Adjust;
            ushortArray[46] = U46_Gate2Adjust;
            ushortArray[47] = U47_End;
            ushortArray[48] = U48_End;
            byte[] byteArray = new byte[ushortArray.Length * sizeof(ushort)];
            Buffer.BlockCopy(ushortArray, 0, byteArray, 0, byteArray.Length);
            return byteArray;
        }
        public byte[] getIo()
        {
            UInt16[] ushortArray = new UInt16[50];
            ushortArray[0] = 0x0505;
            ushortArray[1] = 0x5050;
            ushortArray[2] = U2_ChannelNum;
            ushortArray[3] = U3_StartStop;
            ushortArray[4] = U4_Filter;
            ushortArray[5] = U5_RepetitionFrequency;
            ushortArray[6] = U6_PulseWidth;
            ushortArray[7] = U7_Gain;
            ushortArray[8] = U8_SamplingFrequency;
            ushortArray[9] = U9_PulseDisplacement;
            ushortArray[10] = U10_ScanDepth;
            ushortArray[11] = U11_;
            ushortArray[12] = U12_RepetitionFrequency;
            ushortArray[13] = U13_;
            ushortArray[14] = U14_Gate0Start;
            ushortArray[15] = U15_Gate0Width;
            ushortArray[16] = U16_Gate0Threshold;
            ushortArray[17] = U17_Gate1Start;
            ushortArray[18] = U18_Gate1Width;
            ushortArray[19] = U19_Gate1Threshold;
            ushortArray[20] = U20_Gate2Start;
            ushortArray[21] = U21_Gate2Width;
            ushortArray[22] = U22_Gate2Threshold;
            ushortArray[23] = U23_Gate2Tracking;
            ushortArray[24] = U24_;
            ushortArray[25] = U25_;
            ushortArray[26] = U26_RepetitionFrequency2;
            ushortArray[27] = 0;
            ushortArray[28] = U28_DataType;
            ushortArray[29] = U29_GateMagnify;
            ushortArray[30] = U30_;
            ushortArray[31] = U31_;
            ushortArray[32] = U32_PulseDisplacementH;
            ushortArray[33] = U33_ScanDepthH;
            ushortArray[34] = U34_Gate0StartH;
            ushortArray[35] = U35_Gate0Width;
            ushortArray[36] = U36_Gate1StartH;
            ushortArray[37] = U37_Gate1Width;
            ushortArray[38] = U38_Gate2StartH;
            ushortArray[39] = U39_Gate2WidthH;
            ushortArray[40] = U40_;
            ushortArray[41] = U41_GateTrackingFocus;
            ushortArray[42] = U42_GateTrackingFocusH;
            ushortArray[43] = U43_Synchronous;
            ushortArray[44] = U44_Gate0Adjust;
            ushortArray[45] = U45_Gate1Adjust;
            ushortArray[46] = U46_Gate2Adjust;
            ushortArray[47] = U47_End;
            ushortArray[48] = U48_End;
            byte[] byteArray = new byte[ushortArray.Length * sizeof(ushort)];
            Buffer.BlockCopy(ushortArray, 0, byteArray, 0, byteArray.Length);
            return byteArray;
        }


        //public UInt16 getValueHigh()
        //{

        //}
    }
}
